package assign3.party;

/*****************************************************************
 * Memorial University of Newfoundland<br>
 * 7894 Concurrent Programming<br>
 * Assignment 3, Question 2 - Student Class 
 *
 * @author Dennis Peters ($Author: dpeters $)
 * @version $Revision: 1173 $ $Date: 2010-06-27 23:02:11 -0230 (Sun, 27 Jun 2010) $
 * 
 * $Id: Student.java 1173 2010-06-28 01:32:11Z dpeters $
 ****************************************************************/
class Student implements Runnable 
{
  private Assign3_Bartender server; // Shared by all students and the Runner
  int myId; // student Id

  public Student(Assign3_Bartender s, int id)
    { server = s; myId = id; }

  public void run()
  {
    while (true)
    {
      System.out.println("Student " + myId + " is Thirsty.");
      server.getBeer(myId);
      System.out.println("Student " + myId + " is drinking.");
      drink();
    }
  }

  private void drink()
  {
    try {
      Thread.sleep((int)Math.round(Math.random()*50));
    }
    catch (InterruptedException e) {}
  }
}

